using System;

namespace TSharp.Core.Util.TypeConvert
{
    /// <summary>
    /// NullableSingleTypeDetectorImpl
    /// </summary>
    public class NullableSingleTypeDetectorImpl : NullableValueTypeDetector<float>
    {
        /// <summary>
        /// Strings the specified detector obj.
        /// </summary>
        /// <param name="detectorObj">The detector obj.</param>
        /// <param name="arg">The arg.</param>
        /// <returns></returns>
        public override float? String(string detectorObj, float? arg)
        {
            float result;
            bool parseSucceed = float.TryParse(detectorObj, out result);
            return parseSucceed ? result : arg;
        }

        /// <summary>
        /// Singles the specified detector obj.
        /// </summary>
        /// <param name="detectorObj">The detector obj.</param>
        /// <param name="arg">The arg.</param>
        /// <returns></returns>
        public override Single? Single(Single detectorObj, Single? arg)
        {
            return detectorObj;
        }
    }
}